"""
@name : 3-2.线程锁-信号锁
@author : wenyao
@projectname: sanchuanglianxi
"""
#最多允许同时N个线程执行内容

import threading
import time

num = 0

def task():
    with lock:
        global num
        sleeptime = 3
        print("sleeptime:" ,sleeptime)
        time.sleep(sleeptime)
        num += i
        print(num)

lock = threading.BoundedSemaphore(2)  #定义可以有几个线程去执行
for i in range(6):
    t = threading.Thread(target=task)
    t.start()